jQ(function(){
	jQ("div.my_clips_menu a.memomanage").addClass("memomanageonit");
	var html="";
	for(var i=2020;i>=1950;i--){
		html+="<option value='"+i+"'>"+i+"</option>";
	}
	jQ("#mouth_fun_view_year").empty().append(html);
	getTodayDateInfo();
	initMemoClip();
	analyzeUrl();
	loadAllMemo(0);
	
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
			activeBtnOnDialog("viewopt",true);
		},
		open:function(){
		}
	});
});

function analyzeUrl(){
	var year=eval(getParameter("year"));
	var month=eval(getParameter("month"));
	var day=eval(getParameter("day"));
	if(!isNaN(year)&&year!=null
			&&!isNaN(month)&&month!=null
			&&!isNaN(day)&&day!=null
			){
		getMemoEventsByMonth(year,month,day);
	}else{
		getMemoEventsByMonth(0,0,0);
	}
}

function getTodayDateInfo(){
	jQ.ajax({
		type: "POST",
		url:"calendarAjax!getDateInfo.action",
		success:function(data){
			//getTodayEvent();
			if(data!=null&&data.length>0){
				var dataObj=eval("("+data+")");
				var year=dataObj.year;
				var month=dataObj.month;
				var day=dataObj.dayofmonth;
				jQ("#divtodaydetailtime").data("year",year);
				jQ("#divtodaydetailtime").data("month",month);
				jQ("#divtodaydetailtime").data("date",day);
				
				//tY=dataObj.year;
				//tM=dataObj.month;
				//tD=dataObj.day;
				var weeknum=dataObj.weeknum;
				//getEventsByMonth(year,month);
				
				
				var date=new Date(year, month, day);
				var week=date.getDay();
				var weekStr=day_of_week2cn(week);
				
				var lunarmonth=dataObj.lunarmonth;
				var lunarday=dataObj.lunarday;
				var lunarholidayday=dataObj.lunarholidayday;

				var html="";
				
				html+="<span class='mtime'>今天</span><span>";
				html+=weekStr;
				html+="，";
				html+=year;
				html+="年";
				html+=(month+1);
				html+="月";
				html+=day;
				html+="日，第";
				html+=weeknum;
				html+="周，农历";
				html+=lunarmonth;
				html+="";
				html+=lunarday;
				html+=""
				if(lunarholidayday!=""){
					html+="，"+lunarholidayday+"";
				}
				html+="</span>";
				//jQ("#yeatSelect").val(year).change();;
				jQ("#divtodaydetailtime").empty().append(html);
				
			}
		}
	});
}

function initMemoClip(){
	jQ("li.line a.minus").mousedown(function(){
		jQ(this).addClass("minusdown");
	});
	jQ("li.line a.minus").mouseup(function(){
		jQ(this).removeClass("minusdown");
	});
	jQ("li.line a.plus").mousedown(function(){
		jQ(this).addClass("plusdown");
	});
	jQ("li.line a.plus").mouseup(function(){
		jQ(this).removeClass("plusdown");
	});
	jQ("input.timeipt").val("").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
		var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
		e.dpDiv.css('z-index', z);  
	}});
	jQ("#td_box_quickclip").data("alert",0);
	jQ(".setalert").hide();
}


function getMemoEventsByMonth(yearNum,monthNum,day){
	var vardate=day==0?1:day;
	jQ.ajax({
		type: "POST",
		url:"calendarAjax!getMemoEventsByMonth.action",
		data:{
			year:eval(yearNum),
			month:eval(monthNum)
		},
		success:function(data){
			var year_month=jQ(data).find("year_month").attr("value");
			var year=eval(year_month.split("_")[0]);
			var month=eval(year_month.split("_")[1]);
			jQ("#calendar_monthcontrolbar").data("currentyear",year);
			jQ("#calendar_monthcontrolbar").data("currentmonth",month);
			jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
			jQ("#mouth_fun_view_month option[value='"+(month)+"']").attr("selected",true);
			var firstDateOfMonth=new Date(year,month,1);
			var week2=firstDateOfMonth.getDay();
			var week1=0;
			var startdate=new Date(year,month,1);
			if(week2>week1){
				startdate.setDate(firstDateOfMonth.getDate() -week2);
			}
			
			var endyear,endmonth;
			if(month==11){
				endmonth=0;
				endyear=year+1;
			}else{
				endmonth=month+1;
				endyear=year;
			}
			
			var endDateOfMonth=new Date(endyear,endmonth,1);
			endDateOfMonth.setDate(endDateOfMonth.getDate() -1);
			var week6=6;
			var week5=endDateOfMonth.getDay();
			
			
			var enddate=new Date(endyear,endmonth,1);
			enddate.setDate(enddate.getDate() -1);
			if(week5<week6){
				enddate.setDate(endDateOfMonth.getDate()+ (week6-week5));
			}
			var index=0;
			var tY=eval(jQ("#divtodaydetailtime").data("year"));
			var tM=eval(jQ("#divtodaydetailtime").data("month"));
			var tD=eval(jQ("#divtodaydetailtime").data("date"));
			while(startdate.getTime()<=enddate.getTime()){
				var monthdayObj=jQ("#tdmonth"+index);
				monthdayObj.attr("title",startdate.pattern("yyyy年MM月dd日"));
				var key="month"+startdate.pattern("MMdd");
				monthdayObj.removeClass().attr("classmodel","");
				//monthdayObj.addClass("month"+index);
				monthdayObj.data("date",startdate.getTime());
				var obj=jQ(data).find(key);
				var isThisMonth=eval(obj.find("isThisMonth").text());
				var eventsize=eval(obj.find("memoeventsize").text());
				var isholiday=eval(obj.attr("holiday"));
				var weeknum=eval(obj.find("weeknum").text());
				var weekofmonth=eval(obj.find("weekofmonth").text());
				var weekday=eval(obj.find("weekday").text());
				var lunartxt=obj.find("lunartxt").text();
				/*if(isThisMonth){
					monthdayObj.addClass("normal").addClass("canquick");
				}else{
					monthdayObj.addClass("othermonth").addClass("canquick");
				}*/
				if(!isThisMonth){
					monthdayObj.addClass("other").attr("classmodel","other");
				}
				if(isholiday){
					monthdayObj.addClass("holiday");
				}
				if(eventsize>0){
					jQ("#tdmonth"+index+" div.eventsign").show();
				}else{
					jQ("#tdmonth"+index+" div.eventsign").hide();
				}
				jQ("#tdmonth"+index+" div.sun").empty().append(startdate.getDate());
				if(startdate.getDate()==vardate&&isThisMonth){
					monthdayObj.addClass(monthdayObj.attr("classmodel")+"clickon");
					var month=startdate.getMonth();
					var date=startdate.getDate();
					loadDetailMemoevent(startdate.getFullYear(),month,date);
				}
				jQ("#tdmonth"+index+" div.lunar").empty().append(lunartxt);
				var year=startdate.getFullYear();
				if(year==tY && startdate.getMonth()==tM && startdate.getDate()==tD){
					monthdayObj.addClass("today").attr("classmodel","today");
				}
				index++;
				startdate.setDate(startdate.getDate() +1);
			}
			if(index==28){
				jQ("#monthlast1").hide();
				jQ("#monthlast2").hide();
			}else if(index==35){
				jQ("#monthlast1").show();
				jQ("#monthlast2").hide();
			}else{
				jQ("#monthlast1").show();
				jQ("#monthlast2").show();
			}
			
			jQ("#mouth_fun_prevyear").unbind( "click" );
			jQ("#mouth_fun_prevmonth").unbind( "click" );
			jQ("#mouth_fun_nextyear").unbind( "click" );
			jQ("#mouth_fun_nextmonth").unbind( "click" );
			jQ("#mouth_fun_prevyear").one("click",prevYearClick);
			jQ("#mouth_fun_prevmonth").one("click",prevMonthClick);
			jQ("#mouth_fun_nextyear").one("click",nextYearClick);
			jQ("#mouth_fun_nextmonth").one("click",nextMonthClick);
			jQ("#loadingui").hide();
			jQ("tr.monthcontent td").unbind("click").bind("click",function(){
				if(jQ(this).hasClass("clickon")||jQ(this).hasClass("todayclickon")||jQ(this).hasClass("otherclickon")){
					return;
				}else{
					jQ("tr.monthcontent td[class$=clickon]").removeClass("clickon").removeClass("todayclickon").removeClass("otherclickon");
					var classname=jQ(this).attr("classmodel");
					jQ(this).addClass(classname+"clickon");
					var datetime=eval(jQ(this).data("date"));
					var temp=new Date();
					temp.setTime(datetime);
					var year=temp.getFullYear();
					var month=temp.getMonth();
					var date=temp.getDate();
					loadDetailMemoevent(year,month,date);
				}
			});
		}
	});
}

function loadDetailMemoevent(year,month,date){
	jQ("#smallcalendar").data("date",date);
	var tmp=year;
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!loadDetailMemoevent.action",
		data:{
			year:year,
			month:month,
			date:date
		},
		success:function(data){
			var length=jQ(data).find("EventForView").length;
			if(length>0){
				var html="";
				jQ(data).find("EventForView").each(function(i){
					var eventid=eval(jQ("eventid",this).text());
					var starttime=eval(jQ("starttime",this).text());
					var clocktime=eval(jQ("clocktime",this).text());
					var title=jQ("title",this).text();
					title=htmlData(title);
					if(i%2==0){
						html+="<li eventid='"+eventid+"'>";
					}else{
						html+="<li eventid='"+eventid+"' class='double'>";
					}
					html+="<div class='day'>"+formateDetailTime(starttime)+"</div>";
					html+="<div class='daycontent'>";
					html+="<input type='hidden' value='"+title+"' >";
					html+="<input type='text' value='"+title+"' class='normal'>";
					html+="<span class='errorinfo'></span>";
					html+="</div>";
					html+="<div class='dayopt'>";
					html+="<a class='edit'></a>";
					html+="<a class='del'></a>";
					html+="</div>";
					html+="<div class='clockzone'>";
					if(clocktime>0){
						html+="<span class='clockoff' title='取消提醒'></span>";
						html+="<span>"+formateDetailTimeWithhourmin(clocktime)+"</span>";
					}else{
						html+="<span class='clockon' title='添加提醒'></span>";
					}
					html+="</div>";
					html+="</li>";
				});
				jQ("#somedaycontent").empty().append(html);
				jQ("#somedaycontent li div.clockzone span.clockon").unbind("click").bind("click",showSetClock);
				jQ("#somedaycontent li div.clockzone span.clockoff").unbind("click").bind("click",cancelClock);
				jQ("#somedaycontent li div.daycontent input:text").unbind("click").bind("click",editContent);
				jQ("#somedaycontent li div.daycontent input:text").unbind("blur").bind("blur",updateContent);
				jQ("#somedaycontent li div.dayopt a.edit").unbind("click").bind("click",updateContentClick);
				jQ("#somedaycontent li div.dayopt a.del").unbind("click").bind("click",delMemoClick);
			}else{
				var year=tmp>1900?tmp:tmp+1900;
				var html="<li mid='0'><div class='day'><span style='color:#cdcdcd;'>暂无纪念日</span></div>";
				html+="</li>";
				
				jQ("#somedaycontent").empty().append(html);
			}
			
		}
	});
}

function loadAllMemo(currentpage){
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!loadAllMemoevent.action",
		data:{
			currentpage:currentpage
		},
		success:function(data){
			var length=jQ(data).find("EventForView").length;
			if(length>0){
				var currentpage=eval(jQ("currentpage",data).text());
				var pagecount=eval(jQ("pagecount",data).text());
				jQ("#alldayscontent").data("currentpage",currentpage);
				jQ("#alldayscontent").data("pagecount",pagecount);
				var html="";
				jQ(data).find("EventForView").each(function(i){
					var eventid=eval(jQ("eventid",this).text());
					var starttime=eval(jQ("starttime",this).text());
					var clocktime=eval(jQ("clocktime",this).text());
					var title=jQ("title",this).text();
					title=htmlData(title);
					if(i%2==0){
						html+="<li eventid='"+eventid+"'>";
					}else{
						html+="<li eventid='"+eventid+"' class='double'>";
					}
					html+="<div class='day'>"+formateDetailTime(starttime)+"</div>";
					html+="<div class='daycontent'>";
					html+="<input type='hidden' value='"+title+"' >";
					html+="<input type='text' value='"+title+"' class='normal'>";
					html+="<span class='errorinfo'></span>";
					html+="</div>";
					html+="<div class='dayopt'>";
					html+="<a class='edit'></a>";
					html+="<a class='del'></a>";
					html+="</div>";
					html+="<div class='clockzone'>";
					if(clocktime>0){
						html+="<span class='clockoff' title='取消提醒'></span>";
						html+="<span>"+formateDetailTimeWithhourmin(clocktime)+"</span>";
					}else{
						html+="<span class='clockon' title='添加提醒'></span>";
					}
					html+="</div>";
					html+="</li>";
				});
				jQ("#alldayscontent").empty().append(html);
				
				initPaging(currentpage,pagecount);
				
				jQ("#alldayscontent li div.clockzone span.clockon").unbind("click").bind("click",showSetClock);
				jQ("#alldayscontent li div.clockzone span.clockoff").unbind("click").bind("click",cancelClock);
				jQ("#alldayscontent li div.daycontent input:text").unbind("click").bind("click",editContent);
				jQ("#alldayscontent li div.daycontent input:text").unbind("blur").bind("blur",updateContent);
				jQ("#alldayscontent li div.dayopt a.edit").unbind("click").bind("click",updateContentClick);
				jQ("#alldayscontent li div.dayopt a.del").unbind("click").bind("click",delMemoClick);
			}else{
				var html="<li mid='0'><div class='day'><i style='color:#cdcdcd;'>暂无纪念日</i></div>";
				html+="</li>";
				
				jQ("#alldayscontent").empty().append(html);
			}
		}
	});
	//jQ("#alldayscontent")
}

function initPaging(currentpage,pagec){
	jQ("#pagingcontent").empty();
	jQ("#pagecount").empty();
	var pagecount=pagec;
	if(pagecount==1){
		jQ("#pagingcontent").hide();
		jQ("#pagecount").hide();
		return;
	}else{
		var pagemin=currentpage-2;
		var pagemax=currentpage+2;
		if(pagemin<0){
			pagemin=0;
		}
		if(pagemax>pagecount-1){
			pagemax=pagecount-1;
		}
		var html="";
		html+="<a page='first'><span >&lt;&lt;</span></a>";
		for(var i=pagemin;i<=pagemax;i++){
			if(i==currentpage){
				html+="<b ><span>"+(i+1)+"</span></b>";
			}else
				html+="<a page='"+i+"'><span>"+(i+1)+"</span></a>";
		}
		html+="<a page='last'><span >&gt;&gt;</span></a>";
		jQ("#pagingcontent").append(html);
		jQ("#pagingcontent a").unbind("click").bind("click",function(){
			var page=jQ(this).attr("page");
			var currentpage=0;
			if(page=="first"){
				currentpage=0;
			}else if(page=="last"){
				currentpage=pagecount-1;
			}else{
				currentpage=eval(page);
			}
			loadAllMemo(currentpage);
		});
		jQ("#pagecount").append("共有"+pagecount+"页");
	}
}

function addclip(){
	if(checkClipData()){
		jQ("#loadingui").show();
		setTimeout(function(){
			submitClipData();
			return true;
		},1500);
	}
}

function submitClipData(){
	
	var title=jQ.trim(jQ("#quickcliptitle").val());
	var begindate=jQ("#quickclipdate").datepicker( "getDate" );
	var beginlong=0;
	if(begindate!=null){
		beginlong=begindate.getTime();
	}
	
	var endlong=0;
	var iswholeday=1;
	var alertlong=0;
	var deadlinelong=0;
	var mobilenotice=0;
	var list='';
	var mlist='';
	/*****补充******/
	var eventtype=0;
	var status=1;
	var eventid=0;
	var addressTxt="";
	var contentArea="";
	var isalert=eval(jQ("#td_box_quickclip").data("alert"));
	if(isalert){
		var alertdate=jQ("#quickclipalertdate").datepicker( "getDate" );
		if(alertdate!=null){
			var alerthour=eval(jQ("#quickclipalerthour").val());
			var alertmin=eval(jQ("#quickclipalertmin").val());
			alertdate.setHours(alerthour);
			alertdate.setMinutes(alertmin);
			alertlong=alertdate.getTime();
		}
		if(eval(jQ("#var_hasmobile").val())){
			if(eval(jQ("#quickclipalertmobile").data("mobilenotice"))){
				mobilenotice=1;
			}
		}
	}
	
	jQ.ajax({
		type: "POST",
		url:"eventAjax!submitClipData.action",
		data:{
			eventid:eventid,
			cliptype:2,
			title:title,
			address:addressTxt,
			content:contentArea,
			eventtype:eventtype,
			begintime:beginlong,
			endtime:endlong,
			alerttime:alertlong,
			mobilenotice:mobilenotice,
			deadlinetime:deadlinelong,
			contactlist:list,
			mobilelist:mlist,
			status:eval(status),
			iswholeday:iswholeday
		},
		success:function(data){
			if(data!=null){
				window.onbeforeunload = null;
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					jQ("#td_box_quickclip").hide();
					var year=begindate.getFullYear();
					var month=begindate.getMonth();
					var date=begindate.getDate();
					window.location.href=jQ("#ctxVal").val()+"/myclip/set_ctday.html?year="+year+"&month="+month+"&day="+date;
				}else{
					var errzone=jQ("#quickclipinfo");
					errzone.empty();
					errzone.append("数据错误");
					errzone.show();
				}
				jQ("#loadingui").hide();
			}
		}
	});
}

function checkClipData(){
	
	var flag=true;
	var title=jQ.trim(jQ("#quickcliptitle").val());
	var errzone=jQ("#quickclipinfo");
	if(title==null||title.length<=0){
	 	errzone.empty();
		errzone.append("请输入纪念日内容");
		jQ("#quickcliptitle").one("focus",function(){
			errzone.empty().hide();
		});
		errzone.show();
		return false;
	}else{
		if(title.length>50){
			errzone.empty();
			errzone.append("“内容”应在50字以内");
			jQ("#quickcliptitle").one("focus",function(){
				errzone.empty().hide();
			});
			errzone.show();
		}else
			errzone.empty();
	}
	var beginval=jQ("#quickclipdate").val();
	if(beginval==null||beginval.length<=0){
		errzone.empty();
		errzone.append("请选择纪念日日期");
		jQ("#quickclipdate").one("focus",function(){
			errzone.empty().hide();
		});
		errzone.show();
		return false;
	}else{
		errzone.empty();
	}
	var isalert=eval(jQ("#td_box_quickclip").data("alert"));
	if(isalert){
		var alertdateval=jQ("#quickclipalertdate").val();
		if(alertdateval!=null&&alertdateval.length>0){
			var alertdate=jQ("#quickclipalertdate").datepicker( "getDate" );
			var alerthour=eval(jQ("#quickclipalerthour").val());
			var alertmin=eval(jQ("#quickclipalertmin").val());
			alertdate.setHours(alerthour);
			alertdate.setMinutes(alertmin);
			var alertlong=alertdate.getTime();
			var nowdate=new Date();
			nowdate.setTime(eval(jQ("#var_systemtime").val()));
			if(alertlong<nowdate){
				errzone.empty();
				errzone.append("提醒时间应是将来时间");
				jQ("#quickclipalertdate").one("focus",function(){
					errzone.empty().hide();
				});
				errzone.show();
				return false;
			}else{
				errzone.empty();
			}
		}
	}
	

	return flag;
}

function addClock(){
	var errzone=jQ("#memocliperrorinfo");
	var alertdateval=jQ("#memoclipalertdate").val();
	if(alertdateval==null||alertdateval.length<=0){
		errzone.empty();
		errzone.append("请选择提醒的日期");
		jQ("#memoclipalertdate").one("focus",function(){
			errzone.empty().fadeOut();
		});
		errzone.fadeIn();
		return;
	}
	var alertdate=jQ("#memoclipalertdate").datepicker( "getDate" );
	var alerthour=eval(jQ("#memoclipalerthour").val());
	var alertmin=eval(jQ("#memoclipalertmin").val());
	alertdate.setHours(alerthour);
	alertdate.setMinutes(alertmin);
	var alertlong=alertdate.getTime();
	var nowdate=new Date();
	nowdate.setTime(eval(jQ("#var_systemtime").val()));
	if(alertlong<nowdate){
		errzone.empty();
		errzone.append("提醒时间应是将来时间");
		jQ("#memoclipalertdate").one("focus",function(){
			errzone.empty().fadeOut();
		});
		errzone.fadeIn();
		return;
	}
	var eventid=eval(jQ("#td_box_quickalert").data("eventid"));
	var mobilenotice=0;
	if(eval(jQ("#var_hasmobile").val())){
		if(eval(jQ("#memoclipalertmobile").data("mobilenotice"))){
			mobilenotice=1;
		}
	}
	jQ.ajax({
		type: "POST",
		url:"eventAjax!addEventClock.action",
		data:{
			eventid:eventid,
			alerttime:alertlong,
			mobilenotice:mobilenotice
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#td_box_quickalert").hide();
					var clockobj=jQ("li[eventid="+eventid+"] div.clockzone span");
					clockobj.removeClass().addClass("clockoff");
					clockobj.attr("title","取消提醒");
					clockobj.after("<span>"+formateDetailTimeWithhourmin(alertlong)+"</span>");
					clockobj.unbind("click").bind("click",cancelClock);
				}else{
					
				}
			}
		}
	});
}

function cancelClock(){
	var eventid=eval(jQ(this).parent().parent().attr("eventid"));
	jQ.ajax({
		type: "POST",
		url:"eventAjax!cancelClock.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					var clockobj=jQ("li[eventid="+eventid+"] div.clockzone span");
					clockobj.removeClass().addClass("clockon");
					clockobj.attr("title","添加提醒");
					clockobj.next().remove();
					clockobj.unbind("click").bind("click",showSetClock);
				}else{
				}
			}
		}
	});
}

function editContent(){
	if(jQ(this).hasClass("edit")){
		return;
	}else{
		jQ(this).addClass("edit");
	}
}

function delMemoClick(){
	var curObj=jQ(this);
	var info="确定要删除该纪念日么？";
	var title="删除纪念日";
	var eventid=curObj.parent().parent().attr("eventid");
	jQ("#viewopt").data("eventid",eventid);
	var opt=jQ("#viewopt");
	opt.bind("deleteEvent",deleteMemoEvent);
	opt.data("function","deleteEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title", title);
	jQ("#viewopt").dialog("open");
}

function deleteMemoEvent(){
	var eventid=eval(jQ("#viewopt").data("eventid"));
	jQ.ajax({
		type: "POST",
		url:"eventAjax!deleteEvent.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#viewopt").dialog("close");
					jQ("li[eventid='"+eventid+"']").remove();
					refreshCalendar();
				}else{
					jQ("#viewopt_p").empty().append(dataObj['msg']);
					jQ("#viewopt").dialog("close");
				}
			}
		}
	});
}

function refreshCalendar(){
	var year=jQ("#calendar_monthcontrolbar").data("currentyear");
	var month=jQ("#calendar_monthcontrolbar").data("currentmonth");
	var date=jQ("#smallcalendar").data("date");
	getMemoEventsByMonth(eval(year),eval(month),eval(date));
}

function updateContentClick(){
	jQ(this).parent().prev().find("input:text").click();
}

function updateContent(){
	var orientval=jQ(this).parent().find("input:hidden").val();
	var val=jQ.trim(jQ(this).val());
	var errorinfo=jQ(this).parent().find("span.errorinfo");
	var eventid=eval(jQ(this).parent().parent().attr("eventid"));
	var obj=jQ(this);
	if(val==null||val.length<=0){
		jQ(this).removeClass("edit").val(orientval);
		errorinfo.hide();
	}else if(orientval==val){
		jQ(this).removeClass("edit");
		errorinfo.hide();
	}else{
		if(val.length>50){
			errorinfo.empty();
			errorinfo.append("“内容”应在50字以内");
			errorinfo.show();
			jQ(this).one("focus",function(){
				errorinfo.empty().fadeOut();
			});
			return;
		}
		jQ.ajax({
			type: "POST",
			url:"eventAjax!updateMemoContent.action",
			data:{
				eventid:eventid,
				title:val
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj.result){
						jQ("li[eventid="+eventid+"] div.daycontent input:text").val(val);
						jQ("li[eventid="+eventid+"] div.daycontent input:hidden").val(val);
						obj.removeClass("edit");
						errorinfo.hide();
					}else{
						
					}
				}
			}
		});
	}
}

function showSetClock(){
	var box = jQ(this).offset();
	jQ("#td_box_quickalert").css({"top":box.top+12,"left":box.left-300}).show();
	jQ("#td_box_quickalert").data("eventid",jQ(this).parent().parent().attr("eventid"));
}

function quickaddshow(){
	window.onbeforeunload = leavenotice;
	/*if(eval(jQ("#var_hasmobile").val())){
		jQ("#quickclipalertmobile").show();
	}else{
		jQ("#quickclipalertmobile").hide();
	}*/
	jQ('#td_box_quickclip').show();
}

function setAlertStatusChange(obj){
	if(jQ(obj).hasClass("alert")){
		jQ(obj).removeClass("alert").addClass("alertoff").attr("title","取消提醒");
		jQ(".setalert").fadeIn();
		if(eval(jQ("#var_hasmobile").val())){
			jQ("#quickclipalertmobile").fadeIn();
		}else
			jQ("#quickclipalertmobile").hide();
		jQ("#td_box_quickclip").data("alert",1);
	}else{
		var tmp=obj;
		jQ("#quickclipalertmobile").hide();
		jQ(".setalert").fadeOut("fast",function(){
			setTimeout(function(){
				jQ(tmp).removeClass("alertoff").addClass("alert").attr("title","设置提醒");
			},200);
		});
		jQ("#td_box_quickclip").data("alert",0);
	}
}


function changeMobileStatus(obj){
	if(jQ(obj).hasClass("mobilemsg")){
		jQ(obj).data("mobilenotice",1);
		jQ(obj).removeClass("mobilemsg").addClass("mobilemsgonit").attr("title","取消短信提醒");
	}else{
		jQ(obj).data("mobilenotice",0);
		jQ(obj).removeClass("mobilemsgonit").addClass("mobilemsg").attr("title","短信提醒");
	}
}

function leavenotice(){
	return "";
}

function hideQuickclip(id){
	window.onbeforeunload = null;
	jQ("#"+id).hide();
}

function currentMonthClick(){
	jQ("#loadingui").show();
	var tY=eval(jQ("#divtodaydetailtime").data("year"));
	var tM=eval(jQ("#divtodaydetailtime").data("month"));
	jQ("#mouth_fun_view_year option[value='"+tY+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+tM+"']").attr("selected",true);
	getMemoEventsByMonth(tY, tM,0);
}
function changeMonthView(){
	jQ("#loadingui").show();
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	getMemoEventsByMonth(year, month,0);
	
}

function prevYearClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	year=year-1;
	var month=eval(jQ("#mouth_fun_view_month").val());
	jQ("#mouth_fun_view_year option[value='"+(year)+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function prevMonthClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	if(month==0){
		month=11;
		year=year-1;
	}else{
		month=month-1;
	}
	jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+month+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function nextMonthClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	if(month==11){
		month=0;
		year=year+1;
	}else{
		month=month+1;
	}
	jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+month+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function nextYearClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	year=year+1;
	var month=eval(jQ("#mouth_fun_view_month").val());
	jQ("#mouth_fun_view_year option[value='"+(year)+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}

function formateDetailTime(daytime){
	var day=new Date();
	day.setTime(daytime);
	return day.pattern("MM月dd日");
}

function formateDetailTimeWithhourmin(daytime){
	var day=new Date();
	day.setTime(daytime);
	return day.pattern("yyyy-MM-dd HH:mm");
}